<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户详情</title>

    <link rel="stylesheet" href="http://cdn.viptool.cn/lib/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.css" rel="stylesheet"/>
    <link href="../../resource/lib/imageview/css/imageviewer.css" rel="stylesheet"/>
    <link href="../../resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
          th:href="@{/resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/awesome-bootstrap-checkbox/0.3.5/awesome-bootstrap-checkbox.min.css"
          rel="stylesheet">
    <style>
        .user-close-config {
            height: 40px;
            line-height: 40px;
        }

        .user-close-config .control-label {
            margin-left: 20px;
            font-weight: normal !important;
        }

        .user-close-config label.off {
            background-color: red;
            color: #fff;
            margin-right: 10px;
        }

        .user-close-config label.on {
            background-color: #fff;
            color: #674646;
            border: 1px solid #ccc;
            margin-right: 10px;
        }

        .separator {
            margin: 31px 20px 10px 20px;
            border-bottom: 1px solid #ccc;
        }
    </style>
</head>

<body>
<form id="saveForm">
    <div class="wrapper wrapper-content tooltip-demo">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins m-b-none">
                    <div class="ibox-title" style="vertical-align: bottom;height: 100px;"
                         th:replace="fragments/user_detail_tab::userDetailHeader">
                    </div>
                    <div class="tabs-container">
                        <ul class="nav nav-tabs" th:replace="fragments/user_detail_tab::userDetailTab(${userId},0)">
                        </ul>
                        <div class="tab-content" th:object="${user}">
                            <input type="hidden" id="userId" th:value="*{userId}"/>
                            <div class="tab-pane active">
                                <div class="panel-body">
                                    <form class="form-horizontal" id="basicsConfig">
                                        <!-- 分隔符 -->
                                        <div class="separator">
                                            <label>关闭交易配置</label>
                                        </div>
                                        <div class="user-close-config">
                                            <label class="control-label">关闭当前用户购买零售商品资格</label>
                                            <label class="label off"
                                                   th:if="${useConfig.closeBuyRetailGoodsPermission}">已关闭资格</label>
                                            <label class="label on"
                                                   th:if="${!useConfig.closeBuyRetailGoodsPermission}">未限制</label>
                                            <input name=""
                                                   th:onchange="userHandler.closeUserPower(this,0,[[${useConfig.closeBuyRetailGoodsPermission}]])"
                                                   type="checkbox" class="js-switch"
                                                   th:checked="${useConfig.closeBuyRetailGoodsPermission}" checked/>
                                        </div>
                                        <div class="user-close-config">
                                            <label class="control-label">关闭当前用户购买批发商品资格</label>
                                            <label class="label off"
                                                   th:if="${useConfig.closeBuyWholesaleGoodsPermission}">已关闭资格</label>
                                            <label class="label on"
                                                   th:if="${!useConfig.closeBuyWholesaleGoodsPermission}">未限制</label>
                                            <input name=""
                                                   th:onchange="userHandler.closeUserPower(this,1,[[${useConfig.closeBuyWholesaleGoodsPermission}]])"
                                                   type="checkbox" class="js-switch"
                                                   th:checked="${useConfig.closeBuyWholesaleGoodsPermission}"
                                                   checked/>
                                        </div>
                                        <div class="user-close-config">
                                            <label class="control-label">关闭当前用户委卖批发商品资格</label>
                                            <label class="label off"
                                                   th:if="${useConfig.closeAppointWholesaleGoodsPermission}">已关闭资格</label>
                                            <label class="label on"
                                                   th:if="${!useConfig.closeAppointWholesaleGoodsPermission}">未限制</label>
                                            <input name=""
                                                   th:onchange="userHandler.closeUserPower(this,2,[[${useConfig.closeAppointWholesaleGoodsPermission}]])"
                                                   type="checkbox" class="js-switch"
                                                   th:checked="${useConfig.closeAppointWholesaleGoodsPermission}"
                                                   checked/>
                                        </div>

                                        <div class="user-close-config">
                                            <label class="control-label">同时关闭当前用户伞下所有用户购买零售商品资格</label>
                                            <label class="label off"
                                                   th:if="${useConfig.closeAllBuyRetailGoodsPermission}">已关闭资格</label>
                                            <label class="label on"
                                                   th:if="!${useConfig.closeAllBuyRetailGoodsPermission}">未限制</label>
                                            <input name=""
                                                   th:onchange="userHandler.closeMyAllChildUserPower(this,0,[[${useConfig.closeAllBuyRetailGoodsPermission}]])"
                                                   type="checkbox" class="js-switch"
                                                   th:checked="${useConfig.closeAllBuyRetailGoodsPermission}"
                                                   checked/>
                                        </div>
                                        <div class="user-close-config">
                                            <label class="control-label">同时关闭当前用户伞下所有用户购买批发商品资格</label>
                                            <label class="label off"
                                                   th:if="${useConfig.closeAllBuyWholesaleGoodsPermission}">已关闭资格</label>
                                            <label class="label on"
                                                   th:if="${!useConfig.closeAllBuyWholesaleGoodsPermission}">未限制</label>
                                            <input name=""
                                                   th:onchange="userHandler.closeMyAllChildUserPower(this,1,[[${useConfig.closeAllBuyWholesaleGoodsPermission}]])"
                                                   type="checkbox" class="js-switch"
                                                   th:checked="${useConfig.closeAllBuyWholesaleGoodsPermission}"
                                                   checked/>
                                        </div>
                                        <div class="user-close-config">
                                            <label class="control-label">同时关闭当前用户伞下所有用户委卖批发商品资格</label>
                                            <label class="label off"
                                                   th:if="${useConfig.closeAllAppointWholesaleGoodsPermission}">已关闭资格</label>
                                            <label class="label on"
                                                   th:if="${!useConfig.closeAllAppointWholesaleGoodsPermission}">未限制</label>
                                            <input name=""
                                                   th:onchange="userHandler.closeMyAllChildUserPower(this,2,[[${useConfig.closeAllAppointWholesaleGoodsPermission}]])"
                                                   type="checkbox" class="js-switch"
                                                   th:checked="${useConfig.closeAllAppointWholesaleGoodsPermission}"
                                                   checked/>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script src="http://cdn.viptool.cn/lib/jquery/2.2.4/jquery.min.js"></script>
<script src="http://cdn.viptool.cn/lib/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316(123123)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>
<script src="http://cdn.viptool.cn/lib/moment.js/2.19.2/moment.min.js"></script>
<script src="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.js"></script>
<script src="../../resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
<script src="../../resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js}"></script>
<script src="../../resource/lib/imageview/js/imageviewer.min.js"
        th:src="@{/resource/lib/imageview/js/imageviewer.min.js}"></script>
<script type="text/javascript" th:inline="javascript">
    const apiBase = /*[[@{/user}]]*/  "/user";
    const userId = /*[[${user.userId}]]*/ 0;
</script>

<script type="text/javascript">


    $(function () {
        var viewer = ImageViewer();
        $('.imgView').click(function () {
            var imgSrc = this.src,
                highResolutionImage = $(this).data('high-res-img');

            viewer.show(imgSrc, highResolutionImage);
        });
    });

    var userHandler = {
        /**
         * 关闭用户权限
         */
        closeUserPower: function (obj, closeType, isClose) {
            var self = this;
            isClose = obj.checked;
            self.modifyClass(obj, isClose, false);
            var requestData = {userId: userId, closeType: closeType, isClose: isClose}
            hot.ajax("/user/closeUserPower", requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                } else {
                    hot.tip.error("操作失败");
                    self.modifyClass(obj, isClose, true);
                }
            }, function () {
            }, "post", 300);
        },
        /**
         * 关闭用户所有下面人的权限
         */
        closeMyAllChildUserPower: function (obj, closeType, isClose) {
            var self = this;
            isClose = obj.checked;
            self.modifyClass(obj, isClose, false);
            var requestData = {userId: userId, closeType: closeType, isClose: isClose}
            hot.ajax("/user/closeMyAllChildUserPower", requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                } else {
                    hot.tip.error("操作失败");
                    self.modifyClass(obj, isClose, true);
                }
            }, function () {
            }, "post", 300);
        },
        modifyClass: function (obj, isClose, cancel) {
            if (!cancel) {
                $(obj).siblings(isClose ? "label.on" : "label.off")
                    .addClass(isClose ? "off" : "on")
                    .removeClass(isClose ? "on" : "off")
                    .text(isClose ? "已关闭资格" : "未限制");
            }
            else {
                $(obj).siblings(isClose ? "label.off" : "label.on")
                    .addClass(isClose ? "on" : "off")
                    .removeClass(isClose ? "off" : "on")
                    .text(isClose ? "未限制" : "已关闭资格");
            }
        },
        modifyGoodsWelfare: function (goodsId) {
            var requestData = {
                userId: userId,
                goodsId: goodsId,
                rewardAmount: $("#goods_" + goodsId).val()
            }
            if (typeof(requestData.rewardAmount) == "undefined" && requestData.rewardAmount.length === 0) {
                return;
            }
            hot.ajax("/user/goods/welfare", requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功");
                } else {
                    hot.tip.error(apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        }

    }
</script>
</body>

</html>